<template>
    <view class="weather">
      <view class="hourly_title">24小时预报</view>
      <scroll-view
        scroll-x="true"
        class="hourly"
      >
        <view
          class="h_item"
          v-for="(hour,index) in hourly"
          :key="index"
        >
          <text class="h_time">{{hour.time}}</text>
          <view class="h_img">
            <image
              mode="widthFix"
               :src="hour.imgsrc"
            ></image>
          </view>
          <text class="h_tmp">{{hour.tmp}}°</text>
          <text class="h_wind_dir">{{hour.wind_dir}}</text>
          <text class="h_wind_sc">{{hour.wind_sc}}级</text>
        </view>

      </scroll-view>
    </view>
</template>

<script>
export default {
  name: 'WeatherHourly',
  props: {
    city: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      key: '104051ad798f43dba6ecf77f85d9d109',
      forecast: [],
      now: {
        city: '',
        tmp: '',
        imgsrc: '',
        wind_dir: '',
        wind_sc: '',
        hum: '',
        pres: ''
      },
      hourly: []
    }
  },
  created () {
    this.getHourly(this.city)
  },
  methods: {

    /**
     * 获取24小时天气预报
     */
    getHourly (city) {
      wx.request({
        url:
          'https://free-api.heweather.net/s6/weather/hourly?key=' +
          this.key +
          '&location=' +
          city,
        success: (res) => {
          var arr = res.data.HeWeather6[0].hourly
          var hourly = []
          for (var i = 0; i < arr.length; i++) {
            hourly[i] = {
              imgsrc: `https://moyv.top/wechat/images/weather/${arr[i].cond_code}.png`,
              tmp: arr[i].tmp,
              time: arr[i].time.substring(11),
              wind_dir: arr[i].wind_dir,
              wind_sc: arr[i].wind_sc
            }
          }
          this.hourly = hourly
        }
      })
    }
  }
}
</script>

<style lang="less">

.header {
  background-color: #64c8fa;
  /* background-image: linear-gradient(to right, #64a0f8, #64c8fa); */
  height: 450px;
  padding-top: 32px;
  text-align: center;
}

.top {
  display: flex;
  justify-content: space-between;
  align-content: center;
  align-items: center;
}

.city {
  text-align: center;
  color: white;
  display: inline-block;
  font-size: 52px;
  margin-left: 32px;
}

.search {
  margin-right: 32px;
  border-radius: 8px;
  display: inline-flex;
  justify-content: center;
  align-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.1);
  height: 70px;
}

.search input {
  width: 200px;
  padding: 18px 32px;
  text-align: left;
  color: white;
  display: inline-block;
}

.bt_search {
  border-radius: 0 8px 8px 0;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.1);
  display: inline-flex;
  justify-content: center;
  align-content: center;
  align-items: center;
}

.bt_search icon {
  margin: 8px 18px;
}

.center {
  display: flex;
  justify-content: space-between;
  align-content: center;
  align-items: center;
}

.tmp {
  margin-left: 18px;
  display: inline-block;
  font-size: 180px;
  color: white;
}
.cond-image {
  width: 200px;
  margin-right: 32px;
  margin-top: 32px;
}
.bottom {
  display: flex;
  justify-content: space-between;
  align-content: center;
  align-items: center;
}
.bottom view {
  color: white;
  margin: 32px;
}

.hourly_title {
  font-weight: bold;
  font-size: 42px;
  padding: 18px 32px;
}
.hourly {
  width: 718px;
  margin: 0 18px;
  border-radius: 18px;
  box-shadow: 0.1rem 0.1rem 0.5rem rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  background-color: white;
}
.h_item {
  margin: 18px 0;
  display: inline-block;
  width: 143.5px;
  text-align: center;
  font-size: 28px;
}

.h_img {
  margin: 64px 0;
}

.h_img image {
  width: 60px;
}

.h_item text {
  display: block;
}

.h_time {
  color: gray;
}

.h_wind_dir {
  margin-top: 32px;
}

.h_wind_sc {
  color: gray;
}

.h_tmp {
  color: #027aff;
}

.daily {
  width: 718px;
  white-space: nowrap;
  margin: 0 18px;
  background-color: white;
  border-radius: 18px;
  box-shadow: 0.1rem 0.1rem 0.5rem rgba(0, 0, 0, 0.15);
}

.d_item {
  margin: 18px 0;
  display: inline-block;
  width: 179.5px;
  text-align: center;
  font-size: 28px;
}

.d_item text {
  display: block;
}

.d_date {
  color: gray;
}

.d_wind_dir {
  margin-top: 32px;
}

.d_wind_sc {
  color: gray;
}

.footer {
  font-size: 28px;
  color: gray;
  text-align: center;
  margin-top: 50px;
  margin-bottom: 18px;
}
</style>
